package com.wangzeqi.changliaoba.myself;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.WindowManager;

import com.wangzeqi.changliaoba.base.ActivityCollector;
import com.wangzeqi.changliaoba.login.EnterActivity;

/**
 * Created by dllo on 16/3/4.
 */
public class ForceOfficeReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(final Context context, Intent intent) {
        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
        dialogBuilder.setTitle("退出当前账号");
        dialogBuilder.setMessage("退出畅聊吧后虽不会删除任何历史数据，但、你真的要退出吗");
//        dialogBuilder.setCancelable(false);//设置对话框不可取消
        dialogBuilder.setPositiveButton("残忍退出", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                ActivityCollector.finishAll(); // 销毁所有活动
                Intent intent = new Intent(context, EnterActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent); // 重新启动LoginActivity
            }
        });
        dialogBuilder.setNegativeButton("那再玩会", null);
        AlertDialog alertDialog = dialogBuilder.create();
        // 需要设置AlertDialog的类型,保证在广播接收器中可以正常弹出
        alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        alertDialog.show();
    }
}
